package com.simulation.config;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.simulation.Service.ApiRequestLogService;
import com.simulation.Service.impl.ApiRequestLogServiceImpl;
import com.simulation.intercepter.ApiRequestLogInterceptor;
import com.simulation.intercepter.LogTraceInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Auther: xh
 * @Date: 2019/8/17 06:54
 * @Description:
 */
@Configuration
public class LogConfig implements WebMvcConfigurer {
    @Autowired
    private ObjectMapper objectMapper;

    @Bean
    public LogTraceInterceptor traceInterceptor() {
        return new LogTraceInterceptor();
    }

    @Bean
    public ApiRequestLogService apiRequestLogService() {
        return new ApiRequestLogServiceImpl(objectMapper);
    }

    public ApiRequestLogInterceptor apiRequestLogInterceptor(){
        return new ApiRequestLogInterceptor(apiRequestLogService());
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(traceInterceptor());
        registry.addInterceptor(apiRequestLogInterceptor());
    }
}
